package com.jeeplus.test.jlnu.graduationInfo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.test.jlnu.admissionInfo.domain.entity.AllInfo;
import com.jeeplus.test.jlnu.archivalInfo.domain.entity.ArchParmerter;
import com.jeeplus.test.jlnu.graduationInfo.domain.entity.GraduationPameter;
import com.jeeplus.test.jlnu.graduationInfo.domain.vo.GraduationInfoReqVo;
import com.jeeplus.test.jlnu.graduationInfo.service.GraduationInfoService;
import com.jeeplus.test.tools.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "毕业信息")
@RestController
@Slf4j
@RequestMapping("/graduationInfo")
public class GraduationInfoController {

    @Autowired
    private GraduationInfoService graduationInfoService;

    @ApiOperation("毕业信息分页查询")
    @GetMapping("/page")
    public Page<GraduationInfoReqVo> getGraduationInfoPage(ArchParmerter graduationInfoReqVo, @RequestParam(defaultValue = "1") int pageNum,
                                                           @RequestParam(defaultValue = "10") int pageSize) {
        Page<GraduationInfoReqVo> page = new Page<>(pageNum, pageSize);
        Page<GraduationInfoReqVo> pageResult = graduationInfoService.getGraduationInfoPage(graduationInfoReqVo, page);
        return pageResult;
    }
    @ApiOperation("学历学位查询入口")
    @GetMapping("/searchIn")
    public R searchIn(@RequestParam String name,@RequestParam String idCardNum){
        int i = graduationInfoService.searchIn(name, idCardNum);
        if(i == 1){
            return R.suc("登录成功");
        }else {
            return R.error("9999","未查询到数据");
        }
    }
    @ApiOperation("学历学位内部查询")
    @PostMapping("/internalQueries")
    public Map<String,String> internalQueries(@RequestBody GraduationPameter graduationPameter) throws BadHanyuPinyinOutputFormatCombination {
        return graduationInfoService.internalQueries(graduationPameter);
    }

    @ApiOperation("毕业信息新增")
    @PostMapping("/add")
    public R addGraduationInfo(@RequestBody GraduationInfoReqVo graduationInfoReqVo) {
        int i = graduationInfoService.addGraduationInfo(graduationInfoReqVo);
        if(i>0){
            return R.suc();
        }else {
            return R.error();
        }
    }


    @ApiOperation("毕业信息修改")
    @PostMapping("/updateGraduation")
    public R updateGraduation(@RequestBody GraduationInfoReqVo graduationInfoReqVo){
        int i = graduationInfoService.updateGraduation(graduationInfoReqVo);
        if(i>0){
            return R.suc();
        }else {
            return R.error();
        }
    }


}
